﻿using RefactorThis.GraphDiff;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DemoForGraphDiff
{
    class Program
    {
        static void Main(string[] args)
        {
            Test2();
        }
        static void Test2()
        {
            using (TestEntities1 context = new TestEntities1())
            {
                Student student = context.Student.Where(r => r.Name == "Rainy").First();
                context.AliasName.RemoveRange(student.AliasName);

                AliasName name = new AliasName()
                {
                    Student = student,
                    Name = "123"
                };

                AliasName nam2e = new AliasName()
                {
                    Student = student,
                    Name = "42142"
                };

                student.AliasName.Add(name);
                student.AliasName.Add(nam2e);

                context.SaveChanges();
            }
        }

        static void Test1()
        {
            using (TestEntities1 context = new TestEntities1())
            {

                Student student = context.Student.Where(r => r.Name == "Rainy").First();
                context.Entry(student).State = System.Data.Entity.EntityState.Detached;

                student.Address = context.Student.Where(r => r.Name == "Rainy").First().Address;



                AliasName name = new AliasName()
                {
                    Student = student,
                    Name = "testRainy"
                };

                AliasName nam2e = new AliasName()
                {
                    Student = student,
                    Name = "Rainy875"
                };


                student.Address.Address1 = "Chinese";

                student.AliasName.Add(name);
                student.AliasName.Add(nam2e);



                context.UpdateGraph(student, map => map.OwnedCollection(p => p.AliasName));
                //  context.UpdateGraph(student, map => map.OwnedCollection(p => p.Subject));
                context.UpdateGraph(student, map => map.OwnedEntity(p => p.Address));

                context.SaveChanges();
            }
        }
    }
}
